<?php
    if(isset($_GET['editmode']) && $_GET['editmode'] == true)
        $editmode = true;
    
    if(!isset($showitem) && isset($_GET['showitem']))
        $showitem = $_GET['showitem'];

    if($showitem == 'wedding') $pagecontent = 'wedding';
    elseif($showitem == 'guestbook') $pagecontent = 'guestbook';
    elseif($showitem == 'gifts') $pagecontent = 'gifts';
    else{
        // Get partner profile
        $partnerid = $user->getpartnerid();
        if($partnerid > 0){
            $userpartner = new userclass();
            $userpartner->initwithuserid($partnerid);
            $userpartnerprofile = new userprofileclass();
            $userpartnerprofile->initwithuserid($partnerid);
        }
        
        // If either profile is not found or edit mode is requested, show profile edit mode
        if(!($userprofile->id > 0 && $userpartnerprofile->id > 0)){
            $profilesmissing = true;
            $feedbackmessage = $pleasecompleteprofiles;
        }
            
        if($profilesmissing == true || $editmode == true){
            $pagecontent = 'infoedit';
            $saveprofileurl = 'saveprofiles.php?retpage='.$_SERVER['PHP_SELF'].'&showitem='.$topmenuiteminfo;
        }
        else{
            $pagecontent = 'info';
            $editprofileurl = $_SERVER['PHP_SELF'].'?showitem='.$topmenuiteminfo.'&editmode=1';
        }
    }
    
    function drawgenderoptions($selected){
        global $male, $female;
        $selected == 'm' ? $maleselstr = ' selected="selected"' : $maleselstr = '';
        $selected == 'f' ? $femaleselstr = ' selected="selected"' : $femaleselstr = '';
        
        echo '<option value=""> </option>';
        echo '<option value="m"'.$maleselstr.'>'.$male.'</option>';
        echo '<option value="f"'.$femaleselstr.'>'.$female.'</option>';
    }
    
    function drawdoboptions($start, $end, $selected){
        echo '<option value=""> </option>';
        for($i = $start; $i <= $end; $i++){
            $i == $selected ? $selstr = ' selected="selected"' : $selstr = '';
            echo '<option value="'.$i.'"'.$selstr.'>'.$i.'</option>';
        }
    }
?>
<?php if($pagecontent == 'info'): ?>
    <div class="personalinfotable">
        <table cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td class="heading"><?php echo $profile; ?></td>
                <td class="info"></td>
                <td class="heading"><?php echo $partnerprofile; ?></td>
                <td class="info"></td>
            </tr>
            <tr>
                <td><?php echo $name; ?></td>
                <td><?php echo $user->name; ?></td>
                <td><?php echo $name; ?></td>
                <td><?php echo $userpartner->name; ?></td>
            </tr>
            <tr>
                <td><?php echo $surname; ?></td>
                <td><?php echo $user->surname; ?></td>
                <td><?php echo $surname; ?></td>
                <td><?php echo $userpartner->surname; ?></td>
            </tr>
            <tr>
                <td><?php echo $email; ?></td>
                <td><?php echo $user->email; ?></td>
                <td><?php echo $email; ?></td>
                <td><?php echo $userpartner->email; ?></td>
            </tr>
            <tr>
                <td><?php echo $gender; ?></td>
                <td><?php echo $userprofile->getgender(); ?></td>
                <td><?php echo $gender; ?></td>
                <td><?php echo $userpartnerprofile->getgender(); ?></td>
            </tr>
            <tr>
                <td><?php echo $dob; ?></td>
                <td><?php echo $userprofile->getdob(); ?></td>
                <td><?php echo $dob; ?></td>
                <td><?php echo $userpartnerprofile->getdob(); ?></td>
            </tr>
            <tr>
                <td><?php echo $job; ?></td>
                <td><?php echo $userprofile->job; ?></td>
                <td><?php echo $job; ?></td>
                <td><?php echo $userpartnerprofile->job; ?></td>
            </tr>
            <tr>
                <td><?php echo $town; ?></td>
                <td><?php echo $userprofile->town; ?></td>
                <td><?php echo $town; ?></td>
                <td><?php echo $userpartnerprofile->town; ?></td>
            </tr>
            <tr>
                <td>
                    <form action="<?php echo $editprofileurl; ?>" method="post">
                        <input name="submit" type="submit" value="<?php echo $edit; ?>" />
                    </form>
                </td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
<?php elseif($pagecontent == 'infoedit'): ?>
    <div class="feedbackmessagebox"><?php echo $feedbackmessage; ?></div>
    <div class="personalinfotable">
        <form class="profileform" action="<?php echo $saveprofileurl; ?>" method="post" accept-charset="UTF-8">
            <input type="hidden" name="userid" value="<?php echo $user->id; ?>" />
            <input type="hidden" name="partnerid" value="<?php echo $partnerid; ?>" />
            <table cellpadding="0" cellspacing="0" border="0">
                <tr>
                    <td class="heading"><?php echo $profile; ?></td>
                    <td class="info"></td>
                    <td class="heading"><?php echo $partnerprofile; ?></td>
                    <td class="info"></td>
                </tr>
                <tr>
                    <td><?php echo $name; ?></td>
                    <td><input type="text" name="name" value="<?php echo $user->name; ?>" tabindex="1" /></td>
                    <td><?php echo $name; ?></td>
                    <td><input type="text" name="partnername" value="<?php echo $userpartner->name; ?>" tabindex="10" /></td>
                </tr>
                <tr>
                    <td><?php echo $surname; ?></td>
                    <td><input type="text" name="surname" value="<?php echo $user->surname; ?>" tabindex="2" /></td>
                    <td><?php echo $surname; ?></td>
                    <td><input type="text" name="partnersurname" value="<?php echo $userpartner->surname; ?>" tabindex="11" /></td>
                </tr>
                <tr>
                    <td><?php echo $email; ?></td>
                    <td><input type="text" name="email" value="<?php echo $user->email; ?>" tabindex="3" /></td>
                    <td><?php echo $email; ?></td>
                    <td><input type="text" name="partneremail" value="<?php echo $userpartner->email; ?>" tabindex="12" /></td>
                </tr>
                <tr>
                    <td><?php echo $gender; ?></td>
                    <td>
                        <select name="gender" tabindex="4"><?php drawgenderoptions($userprofile->gender); ?></select>
                    </td>
                    <td><?php echo $gender; ?></td>
                    <td>
                        <select name="partnergender" tabindex="13"><?php drawgenderoptions($userpartnerprofile->gender); ?></select>
                    </td>
                </tr>
                <tr>
                    <td><?php echo $dob; ?></td>
                    <td>
                        <select name="dobyear" tabindex="5"><?php drawdoboptions(1950, 1997, $userprofile->getdobyear()); ?></select>
                        <select name="dobmonth" tabindex="6"><?php drawdoboptions(1, 12, $userprofile->getdobmonth()); ?></select>
                        <select name="dobday" tabindex="7"><?php drawdoboptions(1, 31, $userprofile->getdobday()); ?></select>
                    </td>
                    <td><?php echo $dob; ?></td>
                    <td>
                        <select name="partnerdobyear" tabindex="14"><?php drawdoboptions(1950, 1997, $userpartnerprofile->getdobyear()); ?></select>
                        <select name="partnerdobmonth" tabindex="15"><?php drawdoboptions(1, 12, $userpartnerprofile->getdobmonth()); ?></select>
                        <select name="partnerdobday" tabindex="16"><?php drawdoboptions(1, 31, $userpartnerprofile->getdobday()); ?></select>
                    </td>
                </tr>
                <tr>
                    <td><?php echo $job; ?></td>
                    <td><input type="text" name="job" value="<?php echo $userprofile->job; ?>" tabindex="8" /></td>
                    <td><?php echo $job; ?></td>
                    <td><input type="text" name="partnerjob" value="<?php echo $userpartnerprofile->job; ?>" tabindex="17" /></td>
                </tr>
                <tr>
                    <td><?php echo $town; ?></td>
                    <td><input type="text" name="town" value="<?php echo $userprofile->town; ?>" tabindex="9" /></td>
                    <td><?php echo $town; ?></td>
                    <td><input type="text" name="partnertown" value="<?php echo $userpartnerprofile->town; ?>" tabindex="18" /></td>
                </tr>
                <tr>
                    <td><input type="submit" name="submit" value="<?php echo $save ?>" tabindex="19" /></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        </form>
    </div>
<?php endif; ?>

